//
// Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
//
// GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
//  Author: Shawn.Tan
//  Date : 2025.10.28
//
//  History : Initial Version 2025.10.28
//
//
#ifndef Green_MemoryReservation_H
#define Green_MemoryReservation_H

#include <string>
#include <vector>

#include "Defines.h"
#include "Enums.h"
#include ARCH_ENUM_HEADER

namespace Green {

  class ConstraintSet;
  class VmMapper;

  /*!
    \class MemoryReservation
    \brief The class handles memory reservation information.
  */

  class MemoryReservation {
  public:
    explicit MemoryReservation(const std::string& name); //!< Constructor with name given.
    ~MemoryReservation(); //!< Destructor.
    const std::string& Name() const { return mName; } //!< Return MemoryReservation name.
    const ConstraintSet* GetReservation(EMemBankType memBank) const; //!< Return reservation to a certain memory bank, if any.
    const std::string ToString() const; //!< Return a string representation of the MemoryReservation object.
    void AddConstraint(const std::string& range, EMemBankType memBank); //!< Add constraint in string type.
    void AddVirtualConstraint(const std::string& range, const VmMapper* pVmMapper); //!< Add virtual constraint in string type.
    void AddRange(uint64 start, uint64 size, EMemBankType memBank); //!< Add a reservation range.
    void AddVirtualRange(uint64 start, uint64 size, const VmMapper* pVmMapper); //!< Add a virtual reservation range.
  private:
    MemoryReservation(): mName(), mInitialConstraints(), mCurrentConstraints() { } //!< Default constructor, not meant to be used.
    MemoryReservation(const MemoryReservation& rOther): mName(), mInitialConstraints(), mCurrentConstraints()  { } //!< Copy constructor, not meant to be used.

    inline void CheckBank(EMemBankType memBank) const { //!< Check if a memory bank value is out of bound.
      if (int(memBank) >= mInitialConstraints.size()) {
        BankOutOfBound(memBank);
      }
    }

    void BankOutOfBound(EMemBankType memBank) const; //!< Report a memory bank value out of bound error.
  private:
    std::string mName; //!< Name of memory reservation.
    std::vector<ConstraintSet* > mInitialConstraints; //!< Initial constraints for each bank.
    mutable std::vector<ConstraintSet* > mCurrentConstraints; //!< Current constraints for each bank.
  };

}

#endif
